import { Service } from 'egg';
import { Transaction } from 'sequelize';

class FeedbackService extends Service {
  /**
   * 查找所有feedback
   * @param t 事务
   * @return {conclusionFeedback: []} 各二级分类对应的反馈列表
   */
  async searchAllColusionFeedback(t: Transaction) {
    const { ctx } = this;
    const conclusionFeedback = await ctx.model.Conclusion.findAll({
      include: [
        {
          model: ctx.model.Feedback,
          attributes: [
            'upper',
            'lower',
            'description'],
          raw: false
        }
      ],
      attributes: [
        ['id', 'conclusionId'],
      ],
    }, { transaction: t });

    const feedbackList = conclusionFeedback.map((item) => item.dataValues);

    return feedbackList;
  }
}

module.exports = FeedbackService;
